<?php
require_once('recaptchalib.php');
global $_POST;
global$_SERVER;

class Captcha
{
	// Get a key from https://www.google.com/recaptcha/admin/create
	public 	$publickey = "6LebS_MSAAAAANENqg9YmpbZGO3qaQ3Wg6nl36BK";
	public 	$privatekey = "6LebS_MSAAAAAFtFExMPd7Tg598jU0pH4cVP4Ypb";

	# the response from reCAPTCHA
	public $resp = null;
	# the error code from reCAPTCHA, if any
	public $error = null;

	public function checkCaptcha()
	{
		if ($_POST["recaptcha_response_field"]) {
			$resp = recaptcha_check_answer ($this->privatekey, 
											$_SERVER["REMOTE_ADDR"], 
											$_POST["recaptcha_challenge_field"], 
											$_POST["recaptcha_response_field"]);

			if ($resp->is_valid) {
					return true;
			} else {
					# set the error code so that we can display it
					$this->error = $resp->error;
					return false;
			}
		}		
	}
	
	public function printCaptcha()
	{
		echo recaptcha_get_html($this->publickey, $this->error);
	}
	
}

//TESTE
/* <form action="" method="post">
//<?php
//$teste = new Captcha();
//$teste->printCaptcha();
//var_dump($teste->checkCaptcha());
//?>
//<input type="submit" value="teste" />
//</form>
*/

?>

